package cn.enjoy.mapstructPlus.controller;


import cn.enjoy.mapstructPlus.entity.User;
import cn.enjoy.mapstructPlus.entity.UserVO1;
import cn.enjoy.mapstructPlus.utils.MapstructUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * @author K
 * @date 2025/3/17 下午21:23
 */
@RestController
public class MapstructController {

    @GetMapping("convertEntity")
    public Object convertEntity() {
        User user = new User();
        user.setId(1);
        user.setName("张三");
        user.setCreateTime("2020-04-01 11:05:07");
        user.setUpdateTime(LocalDateTime.now());

        // 使用 mapstruct
        UserVO1 userVO1 = MapstructUtils.convert(user, UserVO1.class);

        return userVO1;
    }

}